home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Embed / Sources / Content.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  8.0 KB  |  296 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Content.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. #ifndef CONTENT_H
  15. #include "Content.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef PROXY_H
  23. #include "Proxy.h"
  24. #endif
  25.  
  26. #ifndef FRAME_H
  27. #include "Frame.h"
  28. #endif
  29.  
  30. #ifndef FWPRESEN_H
  31. #include "FWPresen.h"
  32. #endif
  33.  
  34. #ifndef FWKIND_H
  35. #include "FWKind.h"
  36. #endif
  37.  
  38. #ifndef FWSUSINK_H
  39. #include "FWSUSink.h"
  40. #endif
  41.  
  42. #ifndef FWSUUTIL_H
  43. #include "FWSUUtil.h"
  44. #endif
  45.  
  46. #ifndef FWBUFSIN_H
  47. #include "FWBufSin.h"
  48. #endif
  49.  
  50. // ----- OpenDoc Includes -----
  51.  
  52. #ifndef SOM_Module_OpenDoc_StdProps_defined
  53. #include <StdProps.xh>
  54. #endif
  55.  
  56. //========================================================================================
  57. //    Runtime information
  58. //========================================================================================
  59.  
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment odfembed
  62. #endif
  63.  
  64. FW_DEFINE_AUTO(CEmbedContent)
  65.  
  66. //========================================================================================
  67. //    CLASS CEmbedContent
  68. //========================================================================================
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // CEmbedContent constructor
  72. //----------------------------------------------------------------------------------------
  73.  
  74. CEmbedContent::CEmbedContent(Environment* ev, CEmbedPart* part)
  75. :    FW_CContent(ev, part),
  76.     fEmbedPart(part),
  77.     fProxy(NULL),
  78.     fRotation(0),
  79.     fFacetNumber(1)
  80. {
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. //    CEmbedContent destructor
  85. //----------------------------------------------------------------------------------------
  86.  
  87. CEmbedContent::~CEmbedContent()
  88. {
  89.     delete fProxy;
  90.     fProxy = NULL;
  91. }
  92.  
  93. //----------------------------------------------------------------------------------------
  94. //    CEmbedContent::Externalize
  95. //----------------------------------------------------------------------------------------
  96.  
  97. void CEmbedContent::ExternalizeKind(Environment* ev,
  98.                                  ODStorageUnit* storageUnit,
  99.                                  FW_CKind* kind,
  100.                                  FW_StorageKinds storageKind,
  101.                                  FW_CPromise* promise,
  102.                                  FW_CCloneInfo* cloneInfo)
  103. {
  104. FW_UNUSED(storageKind);
  105. FW_UNUSED(promise);
  106.  
  107.     FW_ASSERT(kind->IsPartKind(ev));    // We only support one kind
  108.  
  109.     // ----- Create a stream -----
  110.     FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, kind->GetType(ev));
  111.     FW_CWritableStream stream(suSink);
  112.     
  113.     // ----- Write number of embedded parts -----
  114.     unsigned long count = (fProxy ? 1 : 0);
  115.     stream << count;
  116.     stream << fRotation;
  117.     stream << fFacetNumber;
  118.     
  119.     // ----- Write embedded part -----
  120.     if (fProxy)
  121.         fProxy->Externalize(ev, suSink->GetStorageUnitView(ev), cloneInfo);
  122.     
  123.     // ----- Delete whatever follows -----
  124.     FW_SUDeleteEndOfFocusedValue(ev, storageUnit);
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. //    CEmbedContent::InternalizeKind
  129. //----------------------------------------------------------------------------------------
  130.  
  131. FW_Boolean CEmbedContent::InternalizeKind(Environment* ev,
  132.                                        ODStorageUnit* storageUnit, 
  133.                                        FW_CKind* kind,
  134.                                        FW_StorageKinds storageKind,
  135.                                        FW_CCloneInfo* cloneInfo)
  136. {
  137. FW_UNUSED(storageKind);
  138.     FW_ASSERT(kind->IsPartKind(ev));    // We only support one kind
  139.  
  140.     // ----- Create a stream -----
  141.     FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, kind->GetType(ev));
  142.     FW_PBufferedSink sink(ev, suSink);
  143.     FW_CReadableStream stream(sink);
  144.     
  145.     // ----- Read number of embedded parts -----
  146.     unsigned long count;
  147.     stream >> count;
  148.     stream >> fRotation;
  149.     stream >> fFacetNumber;
  150.     
  151.     // ----- Read embedded part, if any -----
  152.     if (count == 1)
  153.     {
  154.         fProxy = new CEmbedProxy(ev, fEmbedPart);
  155.         fProxy->Internalize(ev, suSink->GetStorageUnitView(ev), cloneInfo);
  156.     }    
  157.  
  158.     return true;
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    CEmbedContent::ReplaceProxy
  163. //----------------------------------------------------------------------------------------
  164.  
  165. void CEmbedContent::ReplaceProxy(Environment* ev, CEmbedProxy* newProxy)
  166. {
  167.     // ----- Detach existing proxy, if any -----
  168.     if (fProxy)
  169.     {
  170.         fProxy->SetSelectState(ev, false);
  171.         fProxy->DetachEmbeddedFrames(ev);
  172.     }
  173.  
  174.     // ----- Set the proxy  -----
  175.     fProxy = newProxy;    
  176. }
  177.  
  178. //----------------------------------------------------------------------------------------
  179. //    CEmbedContent::IncorporateEmbeddedFrame
  180. //----------------------------------------------------------------------------------------
  181.  
  182. void CEmbedContent::IncorporateEmbeddedFrame(Environment* ev,
  183.                                                 FW_CEmbeddingFrame* scopeFrame,
  184.                                                 ODFrame* odEmbeddedFrame,
  185.                                                 ODShape* suggestedShape,
  186.                                                 ODTypeToken viewType)
  187. {
  188. FW_UNUSED(suggestedShape);
  189. FW_UNUSED(viewType);
  190.     
  191.     // ----- Calculate the frame shape -----
  192.     FW_CAcquiredODShape aqFrameShape = ((CEmbedFrame*)scopeFrame)->CreateFrameShape(ev);
  193.         
  194.     // ----- Create the proxy -----
  195.     CEmbedProxy* newProxy = new CEmbedProxy(ev, fEmbedPart);
  196.  
  197.     // ----- Embed the Part/Frame -----
  198.     // Make sure that if an exception occurs before we complete this method,
  199.     // we dispose of the proxy
  200.     FW_TRY
  201.     {
  202.         newProxy->EmbedFrame(ev, scopeFrame, odEmbeddedFrame, aqFrameShape, viewType);
  203.     }
  204.     FW_CATCH_BEGIN
  205.     FW_CATCH_EVERYTHING () {
  206.         // cleanup in case the Embed failed
  207.         delete newProxy;
  208.         FW_THROW_SAME ();
  209.     }
  210.     FW_CATCH_END
  211.  
  212.     ReplaceProxy(ev, newProxy);
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    CEmbedContent::IncorporateEmbeddedPart
  217. //----------------------------------------------------------------------------------------
  218.  
  219. void CEmbedContent::IncorporateEmbeddedPart(Environment* ev,
  220.                                             FW_CEmbeddingFrame* scopeFrame,
  221.                                             ODPart* odEmbeddedPart, 
  222.                                             ODShape* suggestedShape,
  223.                                             ODTypeToken viewType)
  224. {
  225. FW_UNUSED(suggestedShape);
  226.     
  227.     // ----- Calculate the frame shape -----
  228.     FW_CAcquiredODShape aqFrameShape = ((CEmbedFrame*)scopeFrame)->CreateFrameShape(ev);
  229.         
  230.     // ----- Create the proxy -----
  231.     CEmbedProxy* newProxy = new CEmbedProxy(ev, fEmbedPart);
  232.  
  233.     // ----- Embed the Part/Frame -----
  234.     // Make sure that if an exception occurs before we complete this method,
  235.     // we dispose of the proxy
  236.     FW_TRY
  237.     {
  238.         newProxy->EmbedPart(ev, 
  239.                             scopeFrame->GetPresentation(ev),
  240.                             odEmbeddedPart, 
  241.                             kODFrameObject,        // I want persistent frames
  242.                             aqFrameShape,
  243.                             viewType,
  244.                             NULL,        // no presentation
  245.                             0,            // group id
  246.                             FALSE,        // IsOverlaid
  247.                             FALSE);        // sub frame
  248.     }
  249.     FW_CATCH_BEGIN
  250.     FW_CATCH_EVERYTHING () {
  251.         // cleanup in case the Embed failed
  252.         delete newProxy;
  253.         FW_THROW_SAME ();
  254.     }
  255.     FW_CATCH_END
  256.  
  257.     ReplaceProxy(ev, newProxy);
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. //    CEmbedContent::IsDataOnlyOneProxy
  262. //----------------------------------------------------------------------------------------
  263.  
  264. FW_MProxy* CEmbedContent::IsDataOnlyOneProxy(Environment* ev) const
  265. {
  266. FW_UNUSED(ev);
  267.     return fProxy;
  268. }
  269.  
  270. //----------------------------------------------------------------------------------------
  271. //    CEmbedContent::Rotate
  272. //----------------------------------------------------------------------------------------
  273.  
  274. void CEmbedContent::Rotate(Environment* ev)
  275. {    
  276.     fRotation++;
  277.     fRotation %= 4;
  278.     
  279.     if (fProxy)
  280.         fProxy->RotateFacets(ev, fRotation);
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. //    CEmbedContent::ChangeFacetNumber
  285. //----------------------------------------------------------------------------------------
  286.  
  287. void CEmbedContent::ChangeFacetNumber(Environment* ev, short facetNumber)
  288. {
  289.     if (fProxy)
  290.     {    
  291.         fProxy->HideShow(ev, FALSE);            // hide will remove all the facets    
  292.         fFacetNumber = facetNumber;
  293.         fProxy->HideShow(ev, TRUE);            // Show will recreate the facets    
  294.     }
  295. }
  296.